import {createStore} from 'redux';
import{fromJS,Map,List} from 'immutable';
const imState=fromJS({
    name:'米酒',
    age:2,
    address:{
        city:'武汉',
        region:'青山区'
    },
    hobbies:[
        {name:'芭比娃娃',desc:'可以任人打扮的一个娃娃'},
        {name:'积木',desc:'可以任意组装成自己想要的样子和模型'}
    ]
})

function reducer(state=imState,action){
    switch(action.type){
        case 'DEL_HOBBY':
            return state.update('hobbies',hobbies=>{
                return hobbies.filter(item=>{
                    return action.item!==item
                })
            });
        case 'ADD_HOBBY':
            return state.update('hobbies',hobbies=>{
                console.log(action.item)
                return hobbies.push(Map(action.item))
                
            })

        default:return state
    }
}

const store=createStore(reducer);
export default store;